<?php
require_once("xforms/Core.php");

class XForms_select1 extends XForms_Core {
  protected $tpl = 
  '<div class="xforms_select1{renderClass}">
	{renderHelp}{renderLabel}{required}
	<div>
	<select {renderId} class="radio" {renderReadOnly}>
		{renderOptions}
	</select>
	</div>
	
	<div class="xforms_validationmessage">
	</div>
	
	{renderHint}
	
  </div>';
  
  protected $script = '.append(new XForms_select1({renderJson}))';
  
 function renderClass(){
  $cssClass="";
  $binding = $this->getBinding();
  if($binding && $binding->getAttribute("relevant")) {

    $xBinding = $this->getXElement($binding);
    switch($xBinding->evalAttribute("relevant")){
      case true: break;
      case false: $cssClass= $cssClass . " xforms_nonvisible";break;
      default:
    }
  }
  return $cssClass;
}
  function renderOptions(){
    return parent::renderChildNodes(array('xforms:item','xforms:itemset'));
  }
 
  function renderHelp(){
    return $this->renderChildNodes(array("xforms:help"));
  }
  function renderHint(){
    return $this->renderChildNodes(array("xforms:hint"));
  }
  
  
  
  function renderItems(){
    $e = new Evaluator();
    $tplItem = '<li {renderValue}>{renderLabel}</li>';
    $result = '';
    $i = 0;
    foreach($this->getBindings() as $item) {
      $this->nodesetIndex = $i;
      $result.= $e->evaluate($tplItem, $this);
      $i++;
    }
    return $result;
 }
 
 
 
  function renderValue(){
    return ' value="'.htmlentities($this->renderChildNodes(array("xforms:value")), ENT_QUOTES, 'utf-8').'"';
  }
 
 function prueba(){
    return ' valueddddddddd="'.htmlentities($this->renderChildNodes(array("xforms:value")), ENT_QUOTES, 'utf-8').'"';
  }
 
   function renderLabel(){

    return $this->renderChildNodes(array("xforms:label"));
  }

  
  
  function required(){
  $required="";
  $binding = $this->getBinding();
  if($binding && $binding->getAttribute("required")) {
   $xBinding = $this->getXElement($binding);
    switch($xBinding->evalAttribute("required")) {
      case true: $required='<b style="color:red"> *</b>'; break;
      case false: break;
      default:
    }
  }
  return $required;
}

  function renderReadOnly(){
  $readonly="";
  $binding = $this->getBinding();
  if($binding && $binding->getAttribute("readonly")) {
   $xBinding = $this->getXElement($binding);
    switch($xBinding->evalAttribute("readonly")) {
      case true: $readonly=' readonly="readonly" disabled="disabled"'; break;
      case false: break;
      default:
    }
  }
  return $readonly;
}
  
}
